package cn.hchaojie.camp.javafx.part1;

import java.io.IOException;
import java.net.URL;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class Palette2 extends Application {

	@Override
	public void start(Stage stage) throws Exception {
		Scene scene = new Scene(createContents());
		
		stage.setScene(scene);
		stage.show();
	}
	
	// 在这里创建页面布局
	private Parent createContents() {
		// FXMLLoader.load(getClass().getResource("controller/main.fxml"));
		
		// 这个要放到src/下面
		// URL url = this.getClass()
		//		.getClassLoader()
		//		.getResource("pallete2.fxml");

		// 这个要放到类同一个目录下面
		URL url = this.getClass()
				.getResource("pallete2.fxml");
		VBox root = null;
		try {
			root = FXMLLoader.load(url);
		} catch (IOException e) {
			e.printStackTrace();
		}
				
		return root;
	}
	
	private static void showColor(Circle circle, Label label, double value, int type) {
		Color oldColor = (Color) circle.getFill();

		Color color = null;
		switch (type) {
		case 1:			// red
			color = new Color(value, oldColor.getGreen(), oldColor.getBlue(), 1);
			break;

		case 2:			// green
			color = new Color(oldColor.getRed(), value, oldColor.getBlue(), 1);
			break;

		case 3:			// blue
			color = new Color(oldColor.getRed(), oldColor.getGreen(), value, 1);
			break;
		}
		circle.setFill(color);

		label.setText(String.format("(%3.0f, %3.0f, %3.0f)", 
				color.getRed() * 255, color.getGreen() * 255, color.getBlue() * 255));
	}
	
	public static void main(String[] args) {
		launch(args);
	}
}